package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.entity.Users;
import com.qf.service.UsersService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 2019/10/10
 * Administrator
 * springboot1010
 * 面向对象面向君  不负代码不负卿
 */
@Controller
public class TestController {
    //http://localhost:8080/testjsp?name=xxx
    @Resource
    private UsersService usersService;
    @RequestMapping("/testjsp")
    public String test(@RequestParam(defaultValue = "") String name, int pageindex, ModelMap map){
        System.out.println("testjsp-----------==============合并请求测试");
        map.addAttribute("uname",name);
        List<Users> getall = usersService.getall();
        map.addAttribute("ulist",getall);
        //测试分页
        PageInfo<Users> info = usersService.getallpage(pageindex, 2, name);
        map.addAttribute("pageinfo",info);
        return "show";//show.jsp
    }

    @RequestMapping("test1111111111011")
    public void test1111111111011()
    {
        System.out.println("test1111111111011");
        System.out.println("=================================================");
    }

    @RequestMapping("/insert")
    public String testinsert(String name){
        Users users=new Users();
        users.setUsername(name);
        users.setBirthday(new Date());
        int i = usersService.insertUsers(users);//i表示受影响的行数
        System.out.println("新增数据的id="+users.getUserid());
        return "success";
    }




    @RequestMapping("test111111111019")
    public void test1111111111019()
    {
        System.out.println("test1111111111019");
        System.out.println("=================================================");
    }
}
